<?php
$SITEROOT = '../';
include_once($SITEROOT . 'assets/snippets/shoppingCart/dbconfig.inc.php');
include_once($SITEROOT . 'assets/snippets/shoppingCart/kiwee.class.php');

$kiwee = new Kiwee();

if(IN_MANAGER_MODE!="true") die('<b>' . $_lang['kiwee_include_order_error'] . '</b>');
if ($_SESSION['mgrPermissions']['settings'] != "1") { echo 'Insufficient permissions for this module.'; exit; }

$theme = $manager_theme ? "$manager_theme/":"";
$modx->manager->initPageViewState();
?>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/modal_window/javascripts/modal.js"></script>
<script type="text/javascript" src="actions/includes/interface.js"></script>
<link href="js/modal_window/stylesheets/modal.css" rel="stylesheet" type="text/css" />
<link href="actions/includes/kiwee.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
    function list_add() {
        var poststr = "trxntype=list_add&name=" + urival('name') + "&description=" + urival('desc');
        makePOSTRequest('actions/ajax.php', poststr, 'list_gridreload');
    }

    function list_delete(id){
        if (confirm("Are you sure you want to delete this list?") == true) {
            makePOSTRequest('actions/ajax.php', "trxntype=list_delete&id=" + id, 'list_gridreload');
        }
    }

    function list_gridload(){
        makePOSTRequest('actions/ajax.php', "trxntype=list_gridload", 'list_gridload');
    }

    function list_properties(id) {
        makePOSTRequest('actions/ajax.php', "trxntype=list_properties&id=" + id, 'list_properties');
		showBox();
    }

    function list_update(id){
       var poststr = "trxntype=list_update&id=" + id + "&name=" + urival('uname') + "&description=" + urival('udesc');
       makePOSTRequest('actions/ajax.php', poststr, 'list_gridreload');
       hideBox();
	}

	var listid;
	
	function list_entries(id) {
		listid = id;
		makePOSTRequest('actions/ajax.php', "trxntype=list_entries&id=" + id, 'list_entries');
		showBox();
	}

	//added by Bright @ 20080806 add a line for memo parts
	function list_entries_add(id){
		var poststr = "trxntype=list_entries_add&id=" + id + "&name=" + urival('list_name') + "&value=" +
					 urival('list_value') + "&offset=" + urival('list_offset') + "&memo=" + urival('list_memo');
		makePOSTRequest('actions/ajax.php', poststr, 'list_entries');
	}

	function list_entries_delete(id){
		var poststr = "trxntype=list_entries_delete&listid=" + listid + "&id=" + id;
		makePOSTRequest('actions/ajax.php', poststr, 'list_entries');
	}

	function ajaxrendercomponent(name) {
		if (http_request.responseText.substring(0, 5) == "ERROR") {
			 alert(http_request.responseText);
		} else if (name == 'list_gridload') {
		   document.getElementById('list_grid').innerHTML=http_request.responseText;
		} else if (name == 'list_gridreload') {
			list_gridload();
		} else if (name == 'list_properties') {
			document.getElementById('inner-box').innerHTML=http_request.responseText;
		} else if (name == 'list_entries') {
			document.getElementById('inner-box').innerHTML=http_request.responseText;
		} else {
			alert(name + ": " + http_request.responseText);
		}
	}
	list_gridload();
</script>

<div id="overlay" onclick="hideBox()" style="display:none"></div>
<div id="box" style="display:none">
	<img id="close" src="js/modal_window/images/close.gif" onclick="hideBox()" alt="Close" title="Close this Window" />
	<div id="title" style="color: #ff9933; font-weight: bold; font-size: 14px;">Choice List Properties</div><br />
	<div id="inner-box"></div>
</div>

<div class="kiwee-msc" id="mascot"><a href="http://www.kiweecommerce.org"><img src="actions/includes/Kiwee-small.gif" /></a></div>
<div class="subTitle"></div>
	
<div class="sectionHeader"><?php echo $_lang["kiwee_list_header"]; ?></div>
<div class="sectionBody">
	<p><?php echo $_lang['kiwee_list_desc']; ?></p>
<div>
<br />
	
	<!--<form method="POST">  Edited by Bright @ 20080805-->
		<label><?php echo $_lang['name']; ?>:</label><input id="name" name="name" type="text" length=20 />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<label><?php echo $_lang['description']; ?>:</label><input id="desc" name="desc" type="text" length=100 />
		<button onclick="list_add();"> <?php echo $_lang['add']; ?></button>
		<br /><br />
  	</form>
	<div id="list_grid" name="list_grid" ></div>
</div>
